package com.cy.pj.common.service;

import org.springframework.stereotype.Service;

@Service
public class MailServiceImpl implements  MailService{

    @Override
    public boolean sendMail(String msg) {//OCP(开闭原则-->对扩展开放，对修改关闭)
        //long t1=System.currentTimeMillis();
        System.out.println("send->"+msg);
        //long t2=System.currentTimeMillis();
        //System.out.println("send time:"+(t2-t1));
        return true;
    }

}
//下面的两种设计了解？(基于原生方式实现功能扩展)
//1.自己动手写子类重写父类方法，进行功能扩展
//class TimeMailServiceImpl extends  MailServiceImpl{ //CGLIB
//    @Override
//    public boolean sendMail(String msg) {
//        long t1=System.currentTimeMillis();
//        boolean flag= super.sendMail(msg);
//        long t2=System.currentTimeMillis();
//        System.out.println("send time:"+(t2-t1));
//        return flag;
//    }
//}

//自己写兄弟类对目标对象(兄弟类)进行功能扩展,这种方式又叫组合
class TimeMailServiceImpl implements  MailService{

    private MailService mailService;
    public TimeMailServiceImpl(MailService mailService){
        this.mailService=mailService;
    }
    @Override
    public boolean sendMail(String msg) {
        long t1=System.currentTimeMillis();
        boolean flag=mailService.sendMail(msg);
        long t2=System.currentTimeMillis();
        System.out.println("send time:"+(t2-t1));
        return flag;
    }
}